<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Lz.php';


class LzStr
{
    /**
     *  Returns password hash.
     *
     *  @param  $str    [string] Plain text password.
     *  @param  $salt   [string] Old password to generate identical hash
     *  @return         [string] 64-character hexadecimal number.
     */
    static public
    function pass($str, $salt = NULL)
    {
        if (is_null($salt))
            $salt   = sha1(uniqid(mt_rand(), true));

        $salt   = substr($salt, 0, 24);
        return $salt . sha1("$salt,$str," . strlen($str));
    }


    static public
    function rand($length)
    {
        $ch     = 'abcdefghijklmnopqrstuvwxyz'
                . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                . '~!@#$%^&*()_+=/?{}[]';
        $cnt    = strlen($chars);

        for ($rand = ''; $length-- > 0; $rand .= $ch[mt_rand(0, $cnt - 1)]);
        return $rand;
    }


    static public
    function underscore($str)
    {
        $str    = preg_replace('/[A-Z]/', ' \0', $str);
        $str    = preg_replace('/\s/', '_', $str);
        return strtolower($str);
    }


    static public
    function camel($str)
    {
        $str    = preg_replace('/[^a-z0-9]+/i', ' ', strtolower($str));
        $str    = trim($str);
        $str    = preg_replace('/ (\w)/e', 'strtoupper(\'\1\')', $str);
        return $str;
    }


    static public
    function like($var)
    {
        return is_scalar($var)
                || is_null($var)
                || (is_object($var) && method_exists($var, '__toString'));
    }


    private
    function __construct()
    {}
}

